package com.cmuis.goodguide;

import java.util.HashMap;

/*
 * This class creates the Product object used for storing, showing, and handling
 * individual products pulled from GoodGuide.
 * 
 */

public class Product {
	  
	private String id;
	private String name;
	private String url;
	
	// < Rating Name, Value >
	private HashMap<String,String> ratings = new HashMap<String,String>();
	
	private String brand_name;
	private String brand_id;
	private String company_name;
	private String company_id;
	private String category_name;
	private String category_id;
	private String image_url;  
	
	//getters and setters
	
	/**
	 * Get the GoodGuide ID of the Product ID
	 * @return The GoodGuide Product ID of the current product
	 */
	public String getId(){return id;}
	
	/**
	 * Set the product ID of the current product to the specified id
	 * @param i The GoodGuide Product ID of the current product. Accepts a string
	 */
	public void setId(String i){id = i;}
	
	/**
	 * Get the name of the current product
	 * @return The name of the current product
	 */
	public String getName(){return name;}
	/**
	 * 	Set the name of the current product
	 * @param n The name of the current product
	 */
	public void setName(String n){name = n;}
	
	/**
	 * Get the Product URL for GoodGuide
	 * @return The url of the product on GoodGuide
	 */
	public String getURL(){return url;}
	
	/**
	 * Set the URL of the product
	 * @param u The URL of the product from GoodGuide
	 */
	public void setURL(String u){url = u;}
	
	/**
	 * Get the static url of the product image
	 * @return The static-url of the image of the product
	 */
	public String getImage(){return image_url;}
	
	/**
	 * Set the image-url of the product
	 * @param url The image-url of the product
	 */
	public void setImage(String url){image_url = url;}
	
	
	/**
	 * Get all of the GoodGuide ratings for the current product
	 * @return A hashMap of the different ratings
	 */
	public HashMap<String,String> getRatingMap(){return ratings;}
	
	/**
	 *  Get a specific rating in the product
	 * @param type One of three different types of ratings
	 * @return A string representing the GoodGuide rating for the given type
	 */
	public String getRating(String type){return ratings.get(type);}
	
	/**
	 *  Set a specific rating in the product
	 * @param type One of three different types of ratings
	 * @param value The value to be set for the given type
	 */
	public void setRating(String type, String value){ratings.put(type, value);}
	
	/**
	 * Get the Brand Name of the current Product
	 * @return The Brand Name of the current product
	 */
	public String getBrandName(){return brand_name;}
	
	/**
	 * Set the brand of the given product
	 * @param bn The product brand
	 */
	public void setBrandName(String bn){brand_name = bn;}
	
	/**
	 * Get the product brand
	 * @return The product Brand ID 
	 */
	public String getBrandId(){return brand_id;}
	
	/**
	 * Set the product Brand ID 
	 * @param bi The product brand ID 
	 */
	public void setBrandId(String bi){brand_id = bi;}
	
	/**
	 * Get the name of the company that the product belongs to
	 * @return The name of the company the product belongs to
	 */
	public String getCompanyName(){return company_name;}
	
	/**
	 * Set the name of the company the product belongs to. Accepts a string.
	 * @param cn The name of the company the product belongs to
	 */
	public void setCompanyName(String cn){company_name = cn;}
	
	/**
	 * Get the id of the company that the product belongs to
	 * @return company ID
	 */
	public String getCompanyId(){return company_id;}
	
	/**
	 * Set the id of the company that the product belongs to. Accepts a string.
	 * @param ci Company ID
	 */
	public void setCompanyId(String ci){company_id = ci;}
	
	/**
	 * Get the category of the product. 
	 * @return A string representing the category name
	 */
	public String getCategoryName(){return category_name;}
	
	/**
	 * Set the category name of the product. Accepts a string.
	 * @param cn Compnay Name
	 */
	public void setCategoryName(String cn){category_name = cn;}
	
	/**
	 * Get the category ID of the product. 
	 * @return A string representing the category id
	 */
	public String getCategoryId(){return category_id;}
	
	/**
	 * Set the category id of the product. Accepts a String
	 * @param ci Category ID
	 */
	public void setCategoryId(String ci){category_id = ci;}
	
	
	/**
	 * Flushes/Clears all of the data on a given product object.
	 * 
	 */
	public void flush(){
		name = "";
		id = "";
		url = "";
		ratings.clear();
		brand_name = "";
		brand_id = "";
		category_name = "";
		category_id = "";
		company_name = "";
		company_id = "";
	}
	
	/**
	 * 
	 */
	@Override
	public String toString(){
		return "Name: " + name + "\nCompany name " + company_name + "\nBrand Name " + brand_name +
			"\nCategory Name " + category_name + "\nURL " + url + "\n" + "image url" + image_url + "\n" + displayRating();
	}
	
	/**
	 * 
	 * @return
	 */
	public String displayRating() {
		String tmp = "";
		if(ratings.get("root")!= null)
			tmp = tmp + "Overall Rating: " + ratings.get("root") + "\n"; 
		if(ratings.get("social")!= null)
			tmp = tmp + "Social Rating: " + ratings.get("social") + "\n";
		if(ratings.get("environmental") != null)
			tmp = tmp + "Environmental Rating: " + ratings.get("environmental") + "\n";
		if(ratings.get("health-and-safety") != null)
			tmp = tmp + "Health and Safety: " + ratings.get("health-and-safety") + "\n";
		
		return tmp;
	}
	
	@Override
	/**
	 * 
	 */
	public boolean equals(Object other){
		return id.equals(((Product)other).getId());
	}
}
